package com.StarStudio.Mapper;

import com.StarStudio.Domain.Annualoutput;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AnnualOutputMapper {


//    @Select("SELECT * FROM (SELECT  *  FROM (SELECT op.* FROM annualoutput op, zone_annualoutput zop WHERE op.annualoutput_id = zop.annualoutput_id AND zop.zone_id = #{zoneId}) a ORDER BY  annualoutput_id DESC LIMIT 5) last5 ORDER BY annualoutput_id;")
//    public List<Annualoutput> getByZoneId(Integer zoneId);

    @Select("SELECT  *  FROM (SELECT op.* FROM annualoutput op, zone_annualoutput zop WHERE op.annualoutput_id = zop.annualoutput_id AND zop.zone_id = #{zoneId}) a ORDER BY  annualoutput_id DESC LIMIT 5;")
    public List<Annualoutput> getByZoneId(Integer zoneId);

    @Insert("insert into annualoutput values(null, #{year}, #{annualoutput})")
    @Options(useGeneratedKeys = true)
    public void add(Annualoutput annualoutput);

    @Insert("insert into zone_annualoutput values(#{zoneId}, #{annualOutputId})")
    public void addToZone_AnnualOutput(@Param("zoneId") int zoneId,@Param("annualOutputId") long annualOutputId);

    @Update("update annualoutput set year=#{year},annualoutput=#{annualoutput} where annualoutput_id = #{annualoutputId}")
    public void update(Annualoutput annualoutput);

    @Delete("delete from zone_annualoutput zop where zop.annualoutputid = #{annualOutputId}")
    public void deleteFromZone_AnnualOutput(int annualOutputId);

    @Delete("delete from annualoutput where annualoutput_id = #{annualoutputId}")
    public void delete(int annualOutputId);
}
